package younian.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.GenericGenerator;

/**
 * 帖子信息类
 * 
 * @author Administrator
 *
 */

@Entity
@Table(name = "t_topic")
public class Topic {

	private int id;
	private Section section; // 所属主题
	private User user; // 发帖人
	private String title; // 标题
	private String content; // 内容
	private Date publishTime; // 发布时间
	private Date modifyTime; // 编辑时间
	private int good = 0; // 精华 0：默认，1：精华
	private int top = 0; // 置顶 0：默认，1：置顶
	private List<Reply> replyList = new ArrayList<Reply>(); // 所有回复信息

	@Id
	@GeneratedValue(generator = "_native")
	@GenericGenerator(name = "_native", strategy = "native")
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@ManyToOne
	@JoinColumn(name = "sectionId")
	public Section getSection() {
		return section;
	}

	public void setSection(Section section) {
		this.section = section;
	}

	@ManyToOne
	@JoinColumn(name = "userId")
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(length = 50)
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Lob
	@Column(columnDefinition = "TEXT")
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Date getPublishTime() {
		return publishTime;
	}

	public void setPublishTime(Date publishTime) {
		this.publishTime = publishTime;
	}

	public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}

	@OneToMany(mappedBy = "topic")
	@Cascade(value = { CascadeType.DELETE })
	public List<Reply> getReplyList() {
		return replyList;
	}

	public void setReplyList(List<Reply> replyList) {
		this.replyList = replyList;
	}

	public int getGood() {
		return good;
	}

	public void setGood(int good) {
		this.good = good;
	}

	public int getTop() {
		return top;
	}

	public void setTop(int top) {
		this.top = top;
	}

	@Override
	public String toString() {
		return "Topic [id=" + id + ", section=" + section + ", user=" + user + ", title=" + title + ", content="
				+ content + ", publishTime=" + publishTime + ", modifyTime=" + modifyTime + ", good=" + good + ", top="
				+ top + ", replyList=" + replyList + "]";
	}

}
